package org.example.messagewall.messageController;

import org.example.messagewall.model.MessageInfo;
import org.example.messagewall.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:38917
 * Date:2025/4/12
 * Time:22:47
 */

@RequestMapping("/messageWall")
@RestController
public class MessageController {
    @Autowired
    private MessageService messageService;
    //
    @RequestMapping("/publish")
    public boolean publish(MessageInfo messageInfo){
        System.out.println("接收到参数messageWallObject: " + messageInfo);
        if(!StringUtils.hasLength(messageInfo.getFrom())
                || !StringUtils.hasLength(messageInfo.getTo())
                || !StringUtils.hasLength(messageInfo.getSay())){
            return false;
        }
        Integer ret = messageService.insertMessage(messageInfo);
        return ret != 0;
    }
    //
    @RequestMapping("/getList")
    public List<MessageInfo> getList(){
        return messageService.getMessageInfoAll();
    }
}
